/**
 * $Id: ProdLogServiceImpl.java 3873 2011-08-16 09:39:46Z zhangkangjun $
 */
package com.ibuonline.b2b.product.service;

import java.sql.Date;
import java.sql.Timestamp;

import com.dimeng.common.base.BaseServiceImpl;
import com.ibuonline.b2b.common.enumeration.DealType;
import com.ibuonline.b2b.common.enumeration.ProductOperation;
import com.ibuonline.b2b.entity.ProdLog;

/**
 *
 * @author zhangkangjun
 * @date Aug 5, 2011 6:03:12 PM
 */
public class ProdLogServiceImpl extends BaseServiceImpl<ProdLog> implements ProdLogService {
	private static final String COUNT_PRODUCT_OPERATE = "select count(l.id) from ProdLog l,Product p where p.id = l.prodId and p.dealType = ? and l.companyId = ? and l.operation = ? and l.operateTime between ? and ?";

	/* (non-Javadoc)
	 * @see com.ibuonline.b2b.product.service.ProdLogService#getOperationCount(
	 * java.lang.Integer, com.ibuonline.b2b.common.enumeration.ProductOperation)
	 */
	public int getOperationCount(Integer companyId, ProductOperation operation)
			throws Exception {
		if (companyId == null) {
			throw new IllegalArgumentException("companyId may not be null!");
		}
		if (operation == null) {
			throw new IllegalArgumentException("operation may not be null!");
		}
		Date today = new Date(System.currentTimeMillis());
		
		return dao.getRecordCount(COUNT_PRODUCT_OPERATE,new Object[]{DealType.SELL, companyId, 
				operation, Timestamp.valueOf(today + " 00:00:00"), Timestamp.valueOf(today + " 23:59:59")});
	}
	
	

}
